package com.geovis.emergency.spd.controller.pc;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.geovis.common.auth.util.AuthUtil;
import com.geovis.common.core.api.Result;
import com.geovis.common.core.constant.SwaggerConstants;
import com.geovis.common.core.controller.BaseController;
import com.geovis.emergency.spd.biz.pc.service.IPcMessageService;
import com.geovis.emergency.spd.biz.pc.service.IPcPlottingService;
import com.geovis.emergency.spd.entity.pc.entity.PcPlotting;
import com.geovis.emergency.spd.entity.pc.pojo.constant.PcMessageConstant;
import com.geovis.emergency.spd.entity.pc.pojo.constant.PcPlottingConstant;
import com.geovis.emergency.spd.entity.pc.pojo.dto.PcPlottingSaveUpdateDTO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 应急预案指挥模块-标绘信息 前端控制器
 * </p>
 *
 * @author 曾德实
 * @since 2022-05-05
 */
@RestController
@RequestMapping("/pc/pcPlotting")
@RequiredArgsConstructor
@Api(value = "应急预案指挥模块-标绘信息接口", tags = "应急预案指挥模块-标绘信息接口")
@Slf4j
@Validated
public class PcPlottingController extends BaseController<IPcPlottingService> {

    private final IPcMessageService pcMessageService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "根据演练ID查询点列表", notes = "根据演练ID查询点列表")
    @GetMapping({"/getListByDrillId/{pcDrillId}"})
    public Result getListByDrillId(@PathVariable("pcDrillId") String pcDrillId) {
        return Result.ok(baseService.getListByDrillId(pcDrillId));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = SwaggerConstants.SAVE_VALUE, notes = SwaggerConstants.SAVE_VALUE)
    @PostMapping({"/save"})
    public Result save(@RequestBody @Validated PcPlottingSaveUpdateDTO dto) {
        PcPlotting pcPlotting = BeanUtil.copyProperties(dto, PcPlotting.class);
        if (StrUtil.isEmpty(pcPlotting.getCreateId())) {
            pcPlotting.setCreateId(AuthUtil.getCurrentUserId());
        }
        baseService.saveOrUpdate(pcPlotting);
        if (StrUtil.equals(PcPlottingConstant.TYPE_SHARE, dto.getType())) {
            // 发送socket消息
            pcMessageService.sendSocketMessage(PcMessageConstant.TYPE_DISCUSS_DOWN);
        }
        return Result.ok(pcPlotting);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping({"/removeById/{id}"})
    public Result removeById(@PathVariable("id") String id) {
        baseService.removeById(id);
        // 发送socket消息
        pcMessageService.sendSocketMessage(PcMessageConstant.TYPE_DISCUSS_DOWN);
        return Result.ok();
    }

}
